In this set of exercises, we will work with files from statistical software. The first tasks are about importing data, while the later ones are about labelling and exporting.

1

Import the .sav version of the data from the German General Social Survey - ALLBUS 2021.
You need the haven package for this. The file should be stored in the data folder.

Unlike in flat files, such as CSV, the variables now have labels.

2

Print the labels of the first ten variables in the data set.
You can use a function from the sjlabelled package for this. Remember that you can use [ ] ro subset columns/variables (we only want to print the labels for the first ten variables).

Unfortunately, it’s all in German. Imagine you are a political scientist working on a publication in English, and you are interested in the variable pa01 (left-right self-placement). So you may want to consider translating the variable into English.

3

Change the variable label of pa01 from “LINKS-RECHTS-SELBSTEINSTUFUNG, BEFR.” to “left-right self-placement”.
You can, again, use a function from sjlabelled for this.

Your collaborators ask you to share the data after changing labels and stuff. Unfortunately, they do not use R or SPSS and, hence, asks you to export your data as a Stata file.

4

Export your data as a Stata file.
The haven package provides a function for writing such files that is called and works in a similar way as the corresponding function for importing data in this particular format.